<?php
include "includes/sesiones.php";
include "includes/comunes.php";
require_once("includes/paginator.class.php");
$pages = new Paginator;
//error_reporting(E_ALL);



$where=" where 1=1";
if(isset($_GET['Enviar'])){


  if(isset($_GET['dni']) and $_GET['dni']<>"")
      $where.=" and cliente=".trim($_GET['dni'])." ";
   if(isset($_GET['cre']) and $_GET['cre']<>"")
      $where.=" and id=".trim($_GET['cre'])." ";
   if(isset($_GET['fec']) and $_GET['fec']<>"")
      $where.=" and fecha='".trim($_GET['fec'])."'";
  if(isset($_GET['aut']) and $_GET['aut']<>"")
      $where.=" and autorizacion='".trim($_GET['aut'])."'";
  if(isset($_GET['est']) and $_GET['est']<>0)
      $where.=" and estado=".trim($_GET['est'])." ";
   if(isset($_GET['fin']) and $_GET['fin']<>0)
      $where.=" and financiera=".trim($_GET['fin'])." ";
   if(isset($_GET['tip']) and $_GET['tip']<>0)
      $where.=" and tipoCredito=".trim($_GET['tip'])." ";
   if(isset($_GET['niv']) and $_GET['niv']<>0)
      $where.=" and nivelMorosidad=".trim($_GET['niv'])." ";
   if(isset($_GET['suc']) and $_GET['suc']<>0)
      $where.=" and sucursal=".trim($_GET['suc'])." ";
	

   $sql="select * from creditos ".$where." order by id desc ";

 
   $rescli=  cons_ins($sql);

}
else{

	$sql="select  * from creditos where nivelMorosidad=".trim($_GET['niv'])." order by id desc ";
	

$rescli= cons_ins($sql);



}

$pages->items_total = mysql_num_rows($rescli);
$pages->mid_range = 9;
$pages->paginate();
$rescli= cons_ins($sql.$pages->limit);
//echo  $sql.$pages->limit;

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<!--
  fin estilo scroll-->
<?php include "includes/metas.php";?>
<!--libreria jquery central-->
<script src="jquery-ui/js/jquery-1.9.1.js"></script>
<!--fin libreria central-->
<!--libreria flexigrid-->
<link rel="stylesheet" type="text/css" href="jquery-ui/css/ui-flexigrid/flexigrid.css">
<script type="text/javascript" src="jquery-ui/js/flexigrid.js"></script>
<!--fin libreria-->
<link href="modal/styles/modal-window.css" type="text/css" rel="stylesheet" />
<style>
#loading
{
	position:absolute;
	top:0px;
	right:0px;
	background:#ff0000;
	color:#fff;
	font-size:14px;
	font-familly:Arial;
	padding:2px;
	display:none;
}
</style>
<script language="JavaScript" type="text/javascript">
$(function()
{
$('#flex1').flexigrid({
      colModel : [
                
		{display: 'Nro.', name : 'pedidoID', width : 30, sortable : true, align: 'center'},
		{display: 'Fecha', name : 'fecha', width : 53, sortable : true, align: 'left'},
		{display: 'Nombre y Apellido', name : 'nombre', width : 160, sortable : true, align: 'left'},
		{display: 'Entidad', name : 'entidad', width : 150, sortable : true, align: 'left'},
		{display: 'Ult.Gest', name : 'mtootor', width : 53, sortable : true, align: 'left'},
        {display: 'Deuda', name : 'deuda', width : 60, sortable : true, align: 'left'},
        {display: 'Nivel', name : 'nivel', width : 40, sortable : true, align: 'left'},    
		],
                width: 500,
                height: 1100
              
  });

});
</script>


</head>

<body>
<div class="contenedor">
	<div class="cont">
    	<?php include "includes/head.php";?>
        <?php include "includes/menu.php";?>
        

    	<div class="novedadescont">
<!--            <div class="novedadestitulo">
            	<div class="menuvolver"> <a href="javascript:history.back(1)">Volver Atrás</a></div>
            </div>-->
            <div class="novedadestitulo">
            <div class="novetitulo2">Listado de Gestiones a Realizar</div>
            </div>
           
                <?php
                  if($_GET['credito'])
                      echo '<div class="mensaje">Se ha creado exitosamente el credito Nº <strong>'.$_GET['credito'].'</strong> &nbsp;&nbsp;&nbsp;<a href="ImprimirCredito.php?cre_id='.$_GET['credito'].'" target="_new"><img src="images/imprimir.png" border="0" width="25px" alt="Imprimir"/></a></div>'
                ?>


            
            <div class="formucont">
                 <form id="form1" name="form1" method="get" action="ListarUnSegmento.php">
           	 

              <div class="formlinea">
                <div class="formtxt">Dni</div>
                <div class="formtxt2">
                    <input name="dni" type="text" id="form" size="25" />
					 <input name="niv" type="hidden" id="form" value="<?php echo $_GET['niv'] ?>" size="25" />
                </div>
                </div>


                     <div class="formlinea">
                <div class="formtxt">Nº Credito</div>
                <div class="formtxt2">
                    <input name="cre" type="text" id="form" size="25" />
                </div>
                </div>

                      <div class="formlinea">
                <div class="formtxt">Fecha Otor</div>
                <div class="formtxt2">
                    <input name="fec" type="text" id="form" size="25" />
                </div>
                </div>
                <div class="formlinea">
                <div class="formtxt">Financiera</div>
                <div class="formtxt2">
                   <?php echo listar_financieras();?>
                </div>
                </div>

               <div class="formlinea">
                <div class="formtxt">Sucursal</div>
                <div class="formtxt2">
                   <?php echo listar_sucursales();?>
                </div>
                </div>
                   
                       <div class="formlinea">
                <div class="formtxt"></div>
                <div class="formtxt2">
                   
                </div>
                </div>
                      <div class="formlinea">
                <div class="formtxt">Tipo de Credito</div>
                <div class="formtxt2">
                    <select name="tip">
                        <option selected value="0">Todos</option>
                        <option  value="1">Nuevos</option>
                        <option  value="2">Refinanciados</option>
                     </select>
                </div>
                </div>


                 <div class="botcont">
                <input name="Enviar" class="bot" type="submit" value="Buscar" />
                </div>
                </form>
            </div> 


        	<div class="novedadestitulo">
            	<div class="novetitulo2">Resultado<br>
                </div>
            </div>
            
            <div style="align:left;"> </div>
            <div class="listadocont">
            	<div class="listadocol2">
                    
				 <table id="flex1"style="display:none;width: 80%">

               <tbody>	
					
					
<?php while ($regcli=mysql_fetch_array($rescli)):?>
  <tr >
    <td><?php echo $regcli['id']?></td>
    <td><?php echo format_fec($regcli['fecha'],"/")?></td>
    <td>&nbsp;<?php echo obtener_cliente($regcli['cliente'])?>&nbsp;</td>
    <td><?php echo obtener_financiera($regcli['financiera']) ?></td>
    <td><?php echo obtener_ultima_gestion($regcli['id']) ?></td>
    <td>$ <?php echo obtener_deuda_punitorios($regcli['id'],$regcli['financiera'],$regcli['tipoCredito'])?></td>
	 <td>&nbsp;<?php 
	 if($regcli['nivelMorosidad']>0)
	 echo obtener_nombre_nivel($regcli['nivelMorosidad']);
	 elseif(obtener_deuda_punitorios($regcli['id'],$regcli['financiera'],$regcli['tipoCredito'])<=0)
	 echo "Cancelado";
	 else
	 echo "Al dia";
	 
	 ?></td>
    <td>
<!--     <a href="editarclientes.php?cre_id=<?php //echo $rescli->fields['id']?>"><img src="images/editar.png" border="0" width="25px" alt="Editar" title="Editar"/></a>-->
      <a href="nuevaGestion.php?cre_id=<?php echo $regcli['id']?>&niv=<?php echo $_GET['niv']?>" target="new" onclick="$(this).modal({width:903, height:600}).open(); return false;"><img src="images/nuevo.png" border="0" width="15px" alt="Nueva Gestion" title="Nueva Gestion"/></a>
      <a href="pagocreditos.php?cre_id=<?php echo $regcli['id']?>" target="new"><img src="images/visualizar.png" border="0" width="15px" alt="Visualizar" title="Visualizar"/></a>
      <a href="verGestion.php?cre_id=<?php echo $regcli['id']?>&nro=<?php echo $regcli['GestionId']?>" onclick="$(this).modal({width:903, height:600}).open(); return false;"><img src="images/actualizar.jpg" border="0" width="15px" alt="Visualizar Gestion" title="Visualizar Gestion"/></a>
 
	  <!--     <a href="EliminarCreditos.php?cre_id=<?php //echo $rescli->fields['id']?>"><img src="images/eliminar.jpg" border="0" width="25px" alt="Eliminar" title="Eliminar"/></a>-->

<!--    <a href="#"><img src="images/ref.png" border="0" width="80px"/></a>-->
    </td>
  </tr>
 <?php
  
 endwhile ?>
 <tr>
                       <td colspan="8"><?php echo $pages->display_jump_menu();echo $pages->display_items_per_page();echo $pages->display_pages() ?></td>
                   </tr>
 </tbody>

</table>
                	
<!--                    <a href="#" class="listadolinea">Texto o nombre del listado.</a>                    -->
                </div>
<!--                <div class="listadocol">
                	<a href="#"><img src="images/ed.png" border="0" /></a>
                   <a href="#"><img src="images/vis.png" border="0" /></a>
					<a href="#"><img src="images/imp.png" border="0" /></a>
                	<a href="#"><img src="images/ref.png" border="0" /></a>
                    
                    
                </div>-->

                               </div>
            
            
            
            
        	<div class="novedadesbottom"></div>
        </div>
    
    
    
    
    <div class="separador"></div>
 <?php include "includes/menufooter.php";?>
    
    
	<div id="clearing"></div>    
    </div>
<div id="clearing"></div>
</div>
<script type="text/javascript" language="javascript" src="modal/scripts/modal-window.min.js"></script>   
</body>
</html>
